<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>
  <body>
    <!-- 底层diff算法会进行新旧虚拟Dom更新，
         1.复用相同的节点，创建新的和更新后的节点。
    -->
    <div id="root">
      <h2>人员列表</h2>
      <ul>
        <!-- 遍历数组 -->
        <li v-for="(person, index) in persons" :key="person.id">
          姓名：{{person.name}}, 年龄：{{person.age}}
        </li>
      </ul>
      <h2>汽车信息</h2>
      <!-- 遍历对象 -->
      <ul>
        <li v-for="(value, key) in car">{{key}} : {{value}}</li>
      </ul>
    </div>

    <script>
      new Vue({
        el: "#root",
        data: {
          persons: [
            { id: "001", name: "张三", age: 18 },
            { id: "002", name: "李四", age: 19 },
            { id: "003", name: "王五", age: 20 },
          ],
          car: {
            name: "奥迪",
            price: "70万",
            color: "黑色",
          },
        },
      });
    </script>
  </body>
</html>
